<?php
namespace Admin\Controller;
class DatadictController extends CommonController {

	public function add(){
		if (IS_GET) {
			$model_id = M('datadictcate') -> where('id='.I('category_id')) -> getField('model_id');
			$this -> form('',array('ext_id'=>$model_id));
		}elseif (IS_POST) {
			$this -> ebAdd();
		}
	}

	public function save(){
		if (IS_GET) {
			$data = M('Datadict') -> find(I('id','','intval'));
			$model_id = M('datadictcate') -> where('id='.$data['category_id']) -> getField('model_id');
			$this -> form($data,array('ext_id'=>$model_id));
		}elseif (IS_POST) {
			$this -> ebSave();
		}
	}

	// 修改子分类分类id
	public function _after_save(){
		if (IS_POST) {
			$category_id = I('category_id',-1,'intval');
			if ($category_id) {
				$datas = M('Datadict') -> getField('id,pid,sort',true);
				$subid = subtreeid($datas,I('id','','intval'));
				if (count($subid)) {
					M('Datadict') -> where(array('id'=>array('in',$subid))) -> setField('category_id',$category_id);
				}
			}
		}
	}



}